import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getArticleList } from '@/api/article.js'

export const useArticleManageStore = defineStore('articleManage', () => {
  const articleList = ref([])
  const total = ref()

  const getList = async (params) => {
    const res = await getArticleList(params)
    articleList.value = res.data.data
    articleList.value.forEach(item => {
      if (item.state === '1'){
        item.state = '已发布'
      } else {
        item.state = '草稿'
      }
    })
    total.value = res.data.total
  }

  return {
    articleList,
    getList,
    total
  }
})
